<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-dialog aria-label="{{$ctrl.field.key?'Update':'Create'}} User Field">
  <form name="formCustomField" ng-submit="$ctrl.save()" novalidate>
    <md-dialog-content layout-padding>
      <h4>{{$ctrl.updateAction?'Update':'Create'}} User Field</h4>
      <div layout="column">
        <div layout="row">
          <md-input-container>
            <label>Key</label>
            <input
              ng-model="$ctrl.field.key"
              ng-pattern="/^[a-zA-Z0-9_\-]+$/"
              ng-disabled="$ctrl.updateAction"
              autocomplete="off"
              required
              autocomplete="true"
              md-autofocus="!$ctrl.updateAction"
              placeholder="click to display predifined options"
              list="predefinedKeys"
            />
            <datalist id="predefinedKeys">
              <select>
                <option ng-repeat="predefKey in $ctrl.predefinedKeys" value="{{predefKey}}"></option>
              </select>
            </datalist>
            <span style="font-style: italic; font-size: 12px; color: gray">Authorized characters: [a-z0-9_\-]</span>
          </md-input-container>
        </div>
        <div layout="row">
          <md-input-container flex>
            <label>Label</label>
            <input ng-model="$ctrl.field.label" md-autofocus="$ctrl.updateAction" required />
          </md-input-container>
        </div>
        <div layout="row">
          <md-input-container flex>
            <md-checkbox ng-model="$ctrl.field.required" ng-pattern="pattern"> Required </md-checkbox>
          </md-input-container>
        </div>
        <div layout="row">
          <md-input-container flex>
            <label>Values</label>
            <textarea ng-model="$ctrl.field.values" rows="3" class="custom-user-fields-values"> </textarea>
            <span class="custom-user-fields-values-help">Enter the possible values (if any) separated by a new line</span>
          </md-input-container>
        </div>
      </div>
    </md-dialog-content>
    <md-dialog-actions layout="row">
      <md-button ng-click="$ctrl.cancel()"> Cancel </md-button>
      <md-button type="submit" class="md-raised md-primary" ng-disabled="formCustomField.$invalid">
        {{$ctrl.updateAction?'Update':'Create'}} User Field
      </md-button>
    </md-dialog-actions>
  </form>
</md-dialog>
